package com.study.leetcode;

public class Solution_35 {

    public static int searchInsert(int[] nums, int target) {
        int h = nums.length - 1;
        int l = 0;
        int mid = 0;
        while (h >= l) {
            mid = (l + h) / 2;
            if (nums[mid] == target) {
                return mid;
            } else if (nums[mid] > target) {
                h = mid - 1;
            } else {
                l = mid + 1;
            }
        }
        return h + 1;
    }

    public static void main(String[] args) {
        int[] nums = {1,2};
        int p = searchInsert(nums, 0);
        System.out.println("p = " + p);
    }
}
